home *** CD-ROM | disk | FTP | other *** search
/ Power Tools for Macintosh / Power Tools for Macintosh (SoftBit)(1992).iso / Applications / PCalc 1.0.2 / PCalc Functions < prev    next >
Text File  |  1993-03-25  |  5KB  |  340 lines

  1. ••• PCalc 1.0.2 External Functions by James Thomson
  2.  
  3. This document contains the definitions of the functions that appear under the
  4. 'Functions' menu in PCalc. Refer to the manual for more details on how to write
  5. your own.
  6.  
  7. Each function starts with the line 'def <functionName>' followed by any number
  8. of the commands below, each on a separate line, and is terminated by a line
  9. with a single 'end' on it. Note that if the name has a '/' followed by character
  10. at the end, this will be used as the command-key in the menu.
  11.  
  12. Also, the keyword 'separatorLine' adds a grey separator line to the menu and
  13. 'hierMenu <hierMenuName>' creates a submenu in which the functions that follow
  14. appear. A 'hierEnd' or another 'heirMenu <name>' finishes each submenu. 
  15.  
  16. The maximum number of functions is 512 at the moment in 32 submenus, any extra
  17. will be ignored. Do you really need any more than that?
  18.  
  19. If a function only makes sense in a certain mode, it is a good idea to prefix
  20. the rest of the definition with a 'dec', 'hex' or 'bin' so the calculator will
  21. automatically switch mode. For example 'set x 42' when in hex mode sets
  22. the display to the hex value $42, not to forty-two. If any errors occur (such
  23. as an overflow) when applying a function, the calculator will beep.
  24.  
  25. Look at the function definitions below for examples to make things clearer.
  26.  
  27. Please mail me any functions you write that you think would be useful to others
  28. and I will include them with the next version, credited to you.
  29.  
  30.  
  31. ••• Known Commands
  32.  
  33. x is the name of any register
  34. y is the name of any register or an actual value
  35.  
  36.     set x y : x = y
  37.     clr x : x = 0
  38.  
  39.     add x y : x = x + y
  40.     sub x y : x = x - y
  41.     mul x y : x = x * y
  42.     div x y : x = x / y
  43.     pwr x y : x = x to the power of y
  44.  
  45.     neg x : x = -x
  46.     inv x : x = 1/x
  47.     trn x : x = truncate x to integer
  48.     rnd x : x = round x to nearest integer
  49.  
  50.     fac x : x = factorial of x
  51.     exp x : x = e to the power of x
  52.     log x : x = log base 10 of x
  53.     ln  x : x = natural log of x
  54.  
  55.     sin x : x = sine x
  56.     cos x : x = cosine x
  57.     tan x : x = tangant x
  58.     asn x : x = inverse sine x
  59.     acs x : x = inverse cosine x
  60.     atn x : x = inverse tanget x
  61.  
  62.     + value : shortcut add that works on main register
  63.     - value : shortcut subtract that works on main register
  64.     * value : shortcut multiply that works on main register
  65.     / value : shortcut divide that works on main register
  66.  
  67.     = x y : sets x to 1 if x = y, to 0 otherwise
  68.     > x y : sets x to 1 if x > y, to 0 otherwise
  69.     < x y : sets x to 1 if x < y, to 0 otherwise
  70.     => x y : sets x to 1 if x => y, to 0 otherwise
  71.     <= x y : sets x to 1 if x <= y, to 0 otherwise
  72.  
  73.     dec : change mode to decimal
  74.     hex : change mode to hexadecimal
  75.     bin : change mode to binary
  76.  
  77.     deg : change angle measurement to degrees
  78.     rad : change angle measurement to radians
  79.  
  80. In binary and hex modes only :
  81.  
  82.     and x y : x = bitwise and of x and y
  83.     or  x y : x = bitwise or of x and y
  84.     xor x y : x = bitwise xor of x and y
  85.     not x y : x = bitwise not of x
  86.  
  87.  
  88. ••• Known Registers
  89.  
  90.     x : main register
  91.     m : memory
  92.     y : second memory
  93.  
  94.     r1, r2, ...rF : sixteen registers for storing intermediate results
  95.  
  96.  
  97. ••• Known Constants
  98.  
  99.     PI : value of π
  100.     
  101.  
  102. ••• Function Definitions
  103.  
  104. hierMenu Conversion
  105.  
  106. def Inches to Millimetres
  107. dec
  108. mul x 25.4
  109. end
  110.  
  111. def Millimetres to Inches
  112. dec
  113. div x 25.4
  114. end
  115.  
  116. def Miles to Kilometres
  117. dec
  118. mul x 1.609344
  119. end
  120.  
  121. def Kilometres to Miles
  122. dec
  123. div x 1.609344
  124. end
  125.  
  126. def US Gallons to Litres
  127. dec
  128. mul x 3.785411784
  129. end
  130.  
  131. def Litres to US Gallons
  132. dec
  133. div x 3.785411784
  134. end
  135.  
  136. def Imp Gallons to Litres
  137. dec
  138. mul x 4.54609
  139. end
  140.  
  141. def Litres to Imp Gallons
  142. dec
  143. div x 4.54609
  144. end
  145.  
  146. def Pounds to Kilograms
  147. dec
  148. mul x 0.45359237
  149. end
  150.  
  151. def Kilograms to Pounds
  152. dec
  153. div x 0.45359237
  154. end
  155.  
  156. def Ounces to Grams
  157. dec
  158. mul x 28.349523125
  159. end
  160.  
  161. def Grams to Ounces
  162. dec
  163. div x 28.349523125
  164. end
  165.  
  166. def °F to °C
  167. dec
  168. sub x 32
  169. div x 1.8
  170. end
  171.  
  172. def °C to °F
  173. dec
  174. mul x 1.8
  175. add x 32
  176. end
  177.  
  178. def Degrees to Radians
  179. dec
  180. div x 57.29577951308232
  181. end
  182.  
  183. def Radians to Degrees
  184. dec
  185. mul x 57.29577951308232
  186. end
  187.  
  188. def Megabytes to Bytes
  189. dec
  190. mul x 1048576
  191. end
  192.  
  193. def Bytes to Megabytes
  194. dec
  195. div x 1048576
  196. end
  197.  
  198. hierMenu Trigonometric
  199.  
  200. def Hyperbolic Sine
  201. dec
  202. set r1 x
  203. set r2 x
  204. neg r2
  205. exp r1
  206. exp r2
  207. sub r1 r2
  208. div r1 2
  209. set x r1
  210. end
  211.  
  212. def Hyperbolic Cosine
  213. dec
  214. set r1 x
  215. set r2 x
  216. neg r2
  217. exp r1
  218. exp r2
  219. add r1 r2
  220. div r1 2
  221. set x r1
  222. end
  223.  
  224. def Hyperbolic Tangent
  225. dec
  226. set r1 x
  227. set r2 x
  228. set r3 x
  229. set r4 x
  230. neg r2
  231. neg r4
  232. exp r1
  233. exp r2
  234. exp r3
  235. exp r4
  236. sub r1 r2
  237. add r3 r4
  238. div r1 r3
  239. set x r1
  240. end
  241.  
  242. def Inverse Hyp Sine
  243. dec
  244. set r1 x
  245. pwr x 2
  246. add x 1
  247. pwr x 0.5
  248. add x r1
  249. ln x
  250. end
  251.  
  252. def Inverse Hyp Cosine
  253. dec
  254. set r1 x
  255. pwr x 2
  256. sub x 1
  257. pwr x 0.5
  258. add x r1
  259. ln x
  260. end
  261.  
  262. def Inverse Hyp Tangent
  263. dec
  264. set r1 x
  265. set r2 x
  266. set r3 1
  267. sub r3 r2
  268. add r1 1
  269. div r1 r3
  270. ln r1
  271. div r1 2
  272. set x r1
  273. end
  274.  
  275. def Secant
  276. dec
  277. cos x
  278. inv x
  279. end
  280.  
  281. def Cosecant
  282. dec
  283. sin x
  284. inv x
  285. end
  286.  
  287. def Cotangent
  288. dec
  289. tan x
  290. inv x
  291. end
  292.  
  293. hierMenu Financial
  294.  
  295. def Add VAT at 17.5%
  296. dec
  297. mul x 1.175
  298. end
  299.  
  300. def Round to Nearest
  301. dec
  302. mul x 100
  303. add x 0.5
  304. rnd x
  305. div x 100
  306. end 
  307.  
  308. hierMenu Memory
  309.  
  310. def Clear Memory
  311. set m 0
  312. end
  313.  
  314. def Add Memory
  315. add x m
  316. end
  317.  
  318. def Subtract Memory
  319. sub x m
  320. end
  321.  
  322. def Multiply by Memory
  323. mul x m
  324. end
  325.  
  326. def Divide by Memory
  327. div x m
  328. end
  329.  
  330. def Raise to Memory
  331. pwr x m
  332. end
  333.  
  334.  
  335. ••• End Of Functions
  336.  
  337. By the way, you can remove all the comments in this file to free up some memory
  338. if you need it. Click at the right end of the black strip that says 'PCalc' on
  339. the calculator to display the ammount of free memory available and the memory
  340. used up by the functions.